<?php

namespace app\admin\controller\teacher;

use app\common\controller\Backend;

class Info extends Backend
{
    protected $model = null;

    protected $relationSearch = true;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('Subject.Teacher.Teacher');
        $this->FollowModel = model('Subject.Teacher.Follow');
        $this->BusinessModel = model('Business.Business');
    }

    // 查看
    public function index()
    {
        return $this->view->fetch();
    }

    // 粉丝
    public function follow($ids = null)
    {
     
        if ($this->request->isAjax())
        {
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();

            $this->model = $this->FollowModel;

            $total = $this->model
                ->with(['business'])
                ->where($where)
                ->where(['teacherid' => $ids])
                ->order($sort, $order)
                ->count();

            $list = $this->model
                ->with(['business'])
                ->where($where)
                ->where(['teacherid' => $ids])
                ->order($sort, $order)
                ->limit($offset, $limit)
                ->select();

            $result = array("total" => $total, "rows" => $list);

            return json($result);
        }
        return $this->view->fetch();
    }

    // 评论
    public function comment($ids = null)
    {
        $this->model = $this->CommentModel;

        if ($this->request->isAjax())
        {
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();

            $total = $this->model
                ->with(['business'])
                ->where($where)
                ->where(['subid' => $ids])
                ->order($sort, $order)
                ->count();

            $list = $this->model
                ->with(['business'])
                ->where($where)
                ->where(['subid' => $ids])
                ->order($sort, $order)
                ->limit($offset, $limit)
                ->select();

            $result = array("total" => $total, "rows" => $list);

            return json($result);
        }
        return $this->view->fetch();
    }
}
